package com.laboratory.listener;

import cn.hutool.core.bean.BeanUtil;
import com.laboratory.mapper.LabSubMapper;
import com.laboratory.model.entity.LabSub;
import com.laboratory.model.vo.labSub.LabSubEeVo;
import lombok.extern.slf4j.Slf4j;

/**
 * 实验室分室导入数据监听器
 *
 * @author lucky
 */
@Slf4j
public class LabSubListener extends BaseListener<LabSubEeVo, LabSubMapper> {


    public LabSubListener(LabSubMapper mapper) {
        super(mapper);
    }

    @Override
    protected void saveData() {
        log.info("{} >> {}条数据，开始存储数据库！", this.getClass().getSimpleName(), cachedDataList.size());
        cachedDataList.forEach(item -> {
            LabSub labSub = BeanUtil.copyProperties(item, LabSub.class, "id");
            // TODO 根据实验室名称查询实验室ID
            labSub.setLabId(1);
            mapper.insert(labSub);
        });
    }
}
